package com.meeting.controller.admin;

import com.meeting.dto.UserQueryDTO;
import com.meeting.dto.UserStatusDTO;
import com.meeting.service.CustomerService;
import com.meeting.service.EmpService;
import com.meeting.vo.CustomerVO;
import com.meeting.vo.EmpVO;
import com.meeting.vo.PageResult;
import com.meeting.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/user-manage")
@Tag(name = "管理员用户管理接口")
public class AdminUserManageController {

    @Autowired
    private CustomerService customerService;

    @Autowired
    private EmpService empService;

    @GetMapping("/customers")
    @Operation(summary = "分页查询客户列表")
    public Result listCustomers(UserQueryDTO userQueryDTO) {
        log.info("管理员分页查询客户列表：{}", userQueryDTO);
        PageResult<CustomerVO> customers = customerService.listCustomers(userQueryDTO);
        return Result.success(customers);
    }

    @GetMapping("/employees")
    @Operation(summary = "分页查询员工列表")
    public Result listEmployees(UserQueryDTO userQueryDTO) {
        log.info("管理员分页查询员工列表：{}", userQueryDTO);
        PageResult<EmpVO> employees = empService.listEmployees(userQueryDTO);
        return Result.success(employees);
    }

    @PutMapping("/customer/status")
    @Operation(summary = "更新客户状态")
    public Result updateCustomerStatus(@RequestBody UserStatusDTO userStatusDTO) {
        log.info("管理员更新客户状态：{}", userStatusDTO);
        boolean result = customerService.updateStatus(userStatusDTO);
        return result ? Result.success() : Result.error("更新客户状态失败");
    }

    @PutMapping("/employee/status")
    @Operation(summary = "更新员工状态")
    public Result updateEmployeeStatus(@RequestBody UserStatusDTO userStatusDTO) {
        log.info("管理员更新员工状态：{}", userStatusDTO);
        boolean result = empService.updateStatus(userStatusDTO);
        return result ? Result.success() : Result.error("更新员工状态失败");
    }

    @GetMapping("/customer/{id}")
    @Operation(summary = "获取客户详情")
    public Result getCustomerDetail(@PathVariable Integer id) {
        log.info("管理员获取客户详情，ID：{}", id);
        CustomerVO customer = customerService.getCustomerDetail(id);
        return Result.success(customer);
    }

    @GetMapping("/employee/{id}")
    @Operation(summary = "获取员工详情")
    public Result getEmployeeDetail(@PathVariable Integer id) {
        log.info("管理员获取员工详情，ID：{}", id);
        EmpVO employee = empService.getEmployeeDetail(id);
        return Result.success(employee);
    }
} 